import type { RouteLocationRaw } from "vue-router"

export function useNavigate() {
  const router = useRouter()
  function back(to?: RouteLocationRaw) {
    if (window.history.state.back)
      history.back()
    else if ((typeof navigation === "object" && navigation.canGoBack) || history.length > 1)
      router.back()
    else
      router.replace(to || '/')
  }
  return {
    back
  }
}